package com.orhon.smartcampus.modules.student.fetcher;

import com.orhon.smartcampus.basicComponents.Result;
import com.orhon.smartcampus.basicComponents.service.DateService;
import com.orhon.smartcampus.basicComponents.service.GQLUtil;
import com.orhon.smartcampus.modules.base.entity.Grades;
import com.orhon.smartcampus.modules.base.entity.Periods;
import com.orhon.smartcampus.modules.base.entity.Schools;
import com.orhon.smartcampus.modules.base.gqlModel.GQLGrades;
import com.orhon.smartcampus.modules.base.gqlModel.GQLPeriod;
import com.orhon.smartcampus.modules.base.gqlModel.GQLSchool;
import com.orhon.smartcampus.modules.base.mm.GradeMapper;
import com.orhon.smartcampus.modules.base.mm.PeriodMapper;
import com.orhon.smartcampus.modules.base.mm.SchoolMapper;
import com.orhon.smartcampus.modules.student.dao.ArrivesDao;
import com.orhon.smartcampus.modules.student.dao.EclassHeadteacherDao;
import com.orhon.smartcampus.modules.student.dao.EclassRecordsDao;
import com.orhon.smartcampus.modules.student.dao.SInformationDao;
import com.orhon.smartcampus.modules.student.entity.*;
import com.orhon.smartcampus.modules.student.gqlModel.*;
import com.orhon.smartcampus.modules.student.mm.*;
import com.orhon.smartcampus.modules.teacher.entity.TInformation;
import com.orhon.smartcampus.modules.teacher.gqlModel.GQLTeacher;
import com.orhon.smartcampus.modules.teacher.mm.TeacherMapper;
import com.orhon.smartcampus.modules.user.entity.Users;
import com.orhon.smartcampus.modules.user.gqlModel.GQLUser;
import com.orhon.smartcampus.modules.user.mm.UserMapper;
import com.orhon.smartcampus.utils.ObjectToMap;
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

 @Component
public class EclassRecordsFetcher implements DataFetcher {

	@Autowired
	EclassRecordsDao eclassRecordsDao;

    @Override
    public Object get(DataFetchingEnvironment env) throws Exception {
        int id = Integer.parseInt(env.getArgument("id").toString());

        String hql = "from EclassRecords where deleted_at = null and id = "+id;
        EclassRecords item = eclassRecordsDao.findId(hql, null);
        if(item!=null) {
            GQLStudent gqlStudent =null;
            if(env.getSelectionSet().contains("student")){
                SInformation student = item.getStudent();
                gqlStudent = StudentMapper.MAPPER.toStudent(student);
            }
            GQLUser gqlUser =null;
            if(env.getSelectionSet().contains("users")){
                Users users = item.getUsers();
                gqlUser = UserMapper.MAPPER.mapUser(users);
            }
            GQLEclass gqlEclass =null;
            if(env.getSelectionSet().contains("originalEclass")){
                Eclass eclass = item.getOriginalEclass();
                gqlEclass = EclassMapper.MAPPER.toEclass(eclass);
            }
            GQLEclass gqlEclass1 =null;
            if(env.getSelectionSet().contains("goEclass")){
                Eclass goEclass = item.getGoEclass();
                gqlEclass1 = EclassMapper.MAPPER.toEclass(goEclass);
            }
            GQLEclassRecords gqlEclassRecords = EclassRecordssMapper.MAPPER.toEclassRecords(item);
            gqlEclassRecords.setUsers(gqlUser);
            gqlEclassRecords.setStudent(gqlStudent);
            gqlEclassRecords.setGoEclass(gqlEclass1);
            gqlEclassRecords.setOriginalEclass(gqlEclass);
            System.out.println("iiiii="+gqlEclassRecords);

            return gqlEclassRecords;
        }
		return null;

    }

}
